package com.mz.ozy.adapter;

import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mz.ozy.R;
import com.mz.ozy.bean.HomeMerBean;
import com.mz.ozy.bean.ReciprocityBean;
import com.mz.ozy.utils.ScreenUtil;
import com.mz.ozy.utils.glideUtils.GlideUtils;

import java.util.List;

/**
 * Created by administrator on 2018/11/21.
 */
public class ReciprocityAdapter extends BaseQuickAdapter<ReciprocityBean.GoodsPageBean.PageItemsBean, BaseViewHolder> {


    public ReciprocityAdapter(@Nullable List<ReciprocityBean.GoodsPageBean.PageItemsBean> data) {
        super(R.layout.item_reciprocity_food, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, ReciprocityBean.GoodsPageBean.PageItemsBean item) {
        final LinearLayout rootView = helper.getView(R.id.ll_item_view);
        if (helper.getAdapterPosition() / 2 == 0) {
            rootView.setPadding(0, ScreenUtil.dip2px(mContext, 5), 0, 0);
        } else if (helper.getAdapterPosition() >= getData().size() - 2) {
            rootView.setPadding(0, 0, 0, ScreenUtil.dip2px(mContext, 5));
        } else {
            rootView.setPadding(0, 0, 0, 0);
        }
        helper.setText(R.id.tv_goods_name, item.getTradename());
        helper.setText(R.id.tv_benifit_kind, item.getDescribed());
        if (!TextUtils.isEmpty(item.getWeight())) {
            helper.setText(R.id.tv_unit_price, item.getWeight() + "g");
        } else {
            helper.setText(R.id.tv_unit_price, "");
        }
        helper.setText(R.id.tv_goods_price, item.getPrice() + "兑换券");

        ImageView ivGoodPic = helper.getView(R.id.iv_goods_banner);
        String img_zt = "";
        if (!TextUtils.isEmpty(item.getImg_zt())) {
            final String[] splitImgZt = item.getImg_zt().split(",");
            if (splitImgZt.length > 0) {
                img_zt = splitImgZt[0];
            }
        }
        GlideUtils.loadRoundImg(mContext, ivGoodPic, img_zt, R.mipmap.default_foods_icon, 4);
        helper.addOnClickListener(R.id.ll_item_view);
//        helper.addOnClickListener(R.id.tv_food_exchange);
    }
}
